<template>
  <div>
    <div class="search">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="回答用户">
          <el-input v-model="formInline.user" placeholder="回答用户" clearable />
        </el-form-item>
        <el-form-item label="作者">
          <el-input v-model="formInline.user2" placeholder="作者" clearable />
        </el-form-item>
        <el-form-item label="回答发布时间">
          <el-date-picker
            v-model="value1"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd"
            clearable
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div>
      <el-table
        :data="tableData"
        style="width: 100%"
        :fit="true"
      >
        <el-table-column
          label="回答发布时间"
          width="200"
          align="center"
        >
          <template slot-scope="scope">
            <i class="el-icon-time" />
            <span style="margin-left: 10px">{{ scope.row.createTime }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="问题标题"
          width="250"
          align="center"
        >
          <template slot-scope="scope">
            {{ scope.row.title }}
          </template>
        </el-table-column>
        <el-table-column
          label="回答内容"
          width="580"
          align="center"
        >
          <template slot-scope="scope">
            <div slot="reference" class="name-wrapper" style="height:200px">
              <span v-html="scope.row.content" />
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="回答用户"
          width="180px"
          align="center"
        >
          <template slot-scope="scope">
            <div slot="reference" class="name-wrapper">
              <el-tag size="medium" effect="dark" type="success">{{ scope.row.username }}</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="作者/题主/楼主"
          width="180"
          align="center"
        >
          <template slot-scope="scope">
            <div slot="reference" class="name-wrapper">
              <el-tag size="medium" effect="dark" type="success">{{ scope.row.username1 }}</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="handlePass(scope.row)"
            >查看</el-button>
            <el-dropdown style="margin-left: 10px">
              <el-button type="danger" size="mini">
                操作<i class="el-icon-arrow-down el-icon--right" />
              </el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="delArticle(scope.row)">删除问答</el-dropdown-item>
                <!-- <el-dropdown-item @click.native="ignore(scope.row)">觉得正常</el-dropdown-item> -->
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="paging">
      <el-pagination
        background
        layout="prev, pager, next"
        :total="total"
        :current-page="currentPage"
      />
    </div>
  </div>
</template>

<script>
import { questionAnswerList, delQuestionAnswer } from '@/api/question'
export default {
  data() {
    return {
      small: 'mini',
      formInline: {
        user: '',
        user2: '',
        region: ''
      },
      value1: [],
      value2: [],
      tableData: [],
      total: 1,
      currentPage: 1
    }
  },
  mounted() {
    this.questionAnswerList()
  },
  methods: {
    questionAnswerList() {
      var startTime
      var endTime
      if (this.value1 === null) {
        startTime = null
        endTime = null
      } else {
        startTime = typeof this.value1[0] === 'undefined' ? null : this.value1[0]
        endTime = typeof this.value1[1] === 'undefined' ? null : this.value1[1]
      }
      questionAnswerList({ username: this.formInline.user, _username: this.formInline.user2,
        startTime: startTime, endTime: endTime,
        pageIndex: this.currentPage }).then(res => {
        this.tableData = res.data.list
        this.total = res.data.total
        this.currentPage = res.data.pageNum
      })
    },
    onSubmit() {
      this.questionAnswerList()
    },
    handlePass(qa) {
      // changeStatus({ applicationId: application.id, num: 1 }).then(res => {
      //   this.getUnAuditList()
      // })
      window.open('/#/question/' + qa.questionId)
    },
    handleReject(application) {
      // changeStatus({ applicationId: application.id, num: 2 }).then(res => {
      //   this.getUnAuditList()
      // })
    },
    delArticle(row) {
      delQuestionAnswer({ qaId: row.id }).then(res => {
        this.questionAnswerList()
      })
    }
  }
}
</script>

<style scoped lang="scss">
.search{
  padding-top: 20px;
  padding-left: 20px;
}
.paging {
  margin-top: 30px;
  text-align: center;
}
  .el-dropdown {
    vertical-align: top;
  }
  .el-dropdown + .el-dropdown {
    margin-left: 15px;
  }
  .el-icon-arrow-down {
    font-size: 12px;
  }
</style>
